//
//  ViewController.m
//  创建plist文件
//
//  Created by 梁森 on 2017/11/1.
//  Copyright © 2017年 梁森. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 快捷方式获得session对象
    NSURLSession *session = [NSURLSession sharedSession];
    // http://app.zhongyaojixie.com/index.php/api/cart/getCity?province_id=3
    // http://app.zhongyaojixie.com/index.php/api/cart/getProvince
    NSURL *url = [NSURL URLWithString:@"http://app.zhongyaojixie.com/index.php/api/cart/getCity"];
    // 通过URL初始化task,在block内部可以直接对返回的数据进行处理
    NSURLSessionTask *task = [session dataTaskWithURL:url
                                    completionHandler:^(NSData *data, NSURLResponse *response, NSError* error) {
//                                        NSLog(@"==%@", [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]);
                                        NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
                                        NSArray * arr = dic[@"data"][@"niu_index_response"];
                                        NSLog(@"===arr:%@", arr);
                                       BOOL success = [arr writeToFile:@"/Users/liangseb/Desktop/个人/2.plist" atomically:YES];
                                        if (success == YES) {
                                            NSLog(@"写入成功");
                                        }else{

                                            NSLog(@"写入失败");
                                        }
                                    }];
    
    // 启动任务
    [task resume];

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"测试进行push...");
    NSLog(@"测试命令行push");
    NSString * str1 = @"我是谁";
    NSString * str2 = @"我是谁";
    if ([str1 rangeOfString:str2].location != NSNotFound) {
        NSLog(@"包含");
    }else{
        
        NSLog(@"不包含");
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
